package tec;


abstract class PassagerAbstrait 
    implements Passager, Usager  {
    
 
    
    private final String nom;
    private final int destination;
    private EtatPassager monEtat;
    private Caractere c;
    
    public PassagerAbstrait(String nom, int destination, Caractere c){
	if(destination < 0)
	    throw new IllegalArgumentException("destination negative");
	this.nom = nom;
	this.destination = destination;
	this.c = c;
	monEtat = EtatPassager.DEHORS;
    }

    

    
    
    public String nom() {
	return this.nom;
    }

    

    public boolean estDehors() {
	return monEtat.estExterieur();
    }

    public boolean estAssis(){
	return monEtat.estAssis();
    }

    public boolean estDebout() {
	return monEtat.estDebout();
    }

    public void accepterSortie() {
	if(this.estDehors())
	    throw new IllegalStateException("Passenger Already out");
	monEtat = EtatPassager.DEHORS;
    }

    public void accepterPlaceAssise() {
	if(this.estAssis())
	    throw new IllegalStateException("Passenger Already seated");
	monEtat = EtatPassager.ASSIS;
	
    }

    public void accepterPlaceDebout() {
	if(this.estDebout())
	    throw new IllegalStateException("Passenger Already standing");
	monEtat = EtatPassager.DEBOUT;
    }

    public int distance2Dest(int arret){
	return destination - arret;
    }

    public  void nouvelArret(Bus bus, int numeroArret) throws IllegalStateException{
	
	if(destination <= numeroArret)
	    bus.demanderSortie(this);
	c.choixChangerPlace(bus, numeroArret, this);
	
    }

    public final void monterDans(Transport t) throws TecInvalidException{
	if(!(t instanceof Transport && t instanceof Bus))
	    throw new TecInvalidException("Conversion Bus/Transport Invalide");
	Bus b = (Bus) t;
	try{
	this.choixPlaceMontee(b);
	}
	catch(IllegalStateException e){
	    throw new TecInvalidException(e);
	}
    }

    abstract protected void choixPlaceMontee(Bus b);

    
    
    @Override
	public String toString() {
	
	return nom() + " " + monEtat.toString();
    }
}

